<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // function Student(name, age, sex, classCode) {
        //     this.name = name;
        //     this.age = age;
        //     this.classCode = classCode;

        // }
        // Student.prototype.sayName = function () {
        //     console.log(this.name);
        // }
        // let s10 = new Student("wangcong", 20, "男", 100);
        // let s11 = new Student("wangcong", 20, "男", 100);
        // let s12 = new Student("wangcong", 20, "男", 100);
        // let s13 = new Student("wangcong", 20, "男", 100);
        // let s14 = new Student("wangcong", 20, "男", 100);
        // // 再内存中；
        // // function(){
        // //     console.log(this.name);
        // // }
        // // 也是存储了5份；一模一样的；


        // //像这种 方法；就要放在原型上；节省内存
        // s10.sayName();
        {
            {
                //
                function Person(name, age, sex){
                    this.name = name;
                    this.age = age;
                    this.sex = sex;
                }
                Person.prototype.sayName = function () {
                    console.log(this.name);
                }
                Person.prototype.sayAge = function () {
                    console.log(this.age);
                }
                Person.prototype.saySex = function () {
                    console.log(this.sex);
                }
                Person.prototype.xxx = function () {
                    console.log(100);
                }
                let p=new Person();


                //t
                function Teacher(name, age, sex, workCode) { 
                    Person.call(this,name,age,sex,workCode);                
                    this.workCode = workCode;
                }
                Teacher.prototype=p;
              
                //student
                function Student(name, age, sex, classCode) {  
                    Person.apply(this,[name,age,sex,workCode]);                   
                    this.classCode = classCode;
                }              
                Student.prototype = p;
                Student.prototype.sayClassCode = function () {
                    console.log(this.classCode);
                }


                let s1=new Student("t", 10, "nan", 100)
                s1.sayAge();
                // 再内存中；
                // function(){
                //     console.log(this.name);
                // }
                // 也是存储了5份；一模一样的；
                //像这种 方法；就要放在原型上；节省内存
            }
        }
    </script>
</body>

</html>